package pattern.component;

import java.util.ArrayList;
import java.util.List;

/*
 * @author changfei
 * @date  2023/11/28 15:58
 * @description
 */
public class Menu  extends MenuComponent{


    private List<MenuComponent> menuComponentList=new ArrayList<>();

    public Menu(String name,int level) {
        this.level=level;
        this.name=name;
    }

    @Override
    public void add(MenuComponent menuComponent) {
        menuComponentList.add(menuComponent);
    }

    @Override
    public void remove(MenuComponent menuComponent) {
        menuComponentList.remove(menuComponent);
    }

    @Override
    public void print() {
        for (int i=1;i<level;i++){
            System.out.print("--");
        }
        System.out.println(name);
        for (MenuComponent menuComponent:menuComponentList){
            menuComponent.print();
        }
    }
}
